﻿namespace WebPacker.Packs.Resources
{
	using System;

	public sealed class ContentResource : IResource
	{
		private readonly string name; 
		private string content;
		private DateTime lastModifiedTime;

		public ContentResource(string name)
			: this(name, null, DateTime.Now)
		{
		}

		public ContentResource(string name, string content)
			: this(name, content, DateTime.Now)
		{
		}

		public ContentResource(string name, string content, DateTime lastModifiedTime)
		{
			this.name = name;
			this.content = content;
			this.lastModifiedTime = lastModifiedTime;
		}

		public event EventHandler OnChanged;

		public string Name
		{
			get { return name; }
		}

		public DateTime GetLastModifiedTime()
		{
			return lastModifiedTime;
		}

		public string GetContent()
		{
			return content ?? string.Empty;
		}

		public void SetContent(string content)
		{
			this.SetContent(content, DateTime.Now);
		}

		public void SetContent(string content, DateTime lastModifiedTime)
		{
			this.content = content;
			this.lastModifiedTime = lastModifiedTime;

			if (OnChanged != null)
			{
				OnChanged(this, new EventArgs());
			}
		}
	}
}
